package com.softa.common.sysconfig.properties;

import com.softa.common.constant.Constants;
import com.softa.common.sysconfig.support.ShiroFilterBean;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * description goes here.
 *
 * @author 杨磊
 * @date 2019/5/11 10:42
 * @since 1.0
 **/
@Data
@Component
@ConfigurationProperties(prefix = "panda.core")
public class PandaCoreProperties {

    private Shiro shiro;

    @Data
    public  static  class Shiro{

        private String algorithmName;

        private Integer hashIterations;

        private String anonFilter;

        private String otherFilter;

    }

    /**
     * 设置不拦截的文件
     * @return
     */
    public List<String> getShiroAnonFilter(){
        String anonFilter = this.shiro.getAnonFilter();
        List<String> list = new ArrayList<>();
        if(StringUtils.isNotEmpty(anonFilter)){
            String[] arr = anonFilter.split(Constants.SPLIT_COMM);
            for (String str : arr){
                list.add(str);
            }
        }
        return list;
    }

    /**
     * 其他的filter
     * @return
     */
    public List<ShiroFilterBean> getShiroOtherFilter(){
        String otherFilter = this.shiro.getOtherFilter();
        List<ShiroFilterBean> list = new ArrayList<>();
        if(StringUtils.isNotEmpty(otherFilter)){
            String[] arr = otherFilter.split(Constants.SPLIT_COMM);
            for (String str : arr){
                ShiroFilterBean bean = new ShiroFilterBean();
                String[] v = otherFilter.split(Constants.SPLIT_EQ);
                bean.setUrl(v[0].trim());
                bean.setFilter(v[1].trim());
                list.add(bean);
            }
        }
        return list;
    }

}
